package com.qf.controller;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;
import com.qf.utils.MyFactory;

public class UserController {

    public static void main(String[] args) throws Exception {

        //依赖service层的对象，去实现具体的业务功能
//        UserService userService = new UserServiceImpl();

        //加载指定的class文件，返回一个该class文件对应的Class类型的对象
//        Class<?> clazz = Class.forName("com.qf.service.impl.UserServiceImpl");
//
//        UserService userService =(UserService) clazz.newInstance();

        MyFactory myFactory = new MyFactory();

        UserServiceImpl userService = (UserServiceImpl)myFactory.getBean("userService");

        //控制：1、创建对象的过程  2、对象之间的依赖关系的维护
        userService.setUserDao(new UserDaoImpl());

//        UserService userService1 =( UserService)myFactory.getBean("userService");

//        System.out.println(userService == userService1);

//        UserDao userDao = (UserDao) myFactory.getBean("userDao");
//        userDao.inserUser();

        //调用业务对象的方法
        userService.insertUser();
    }
}
